package com.shrcl.engineerprocess.domain.impl;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.CostEstimationProcesss;
import com.shrcl.engineerprocess.domain.EngineerCostEstimation;
import com.shrcl.engineerprocess.domain.ServiceRequestInfo;
import com.shrcl.engineerprocess.domain.TSCProcessRole;
import com.shrcl.engineerprocess.domain.TSCProcessRoleDAO;
import com.shrcl.engineerprocess.domain.impl.EngineerCostEstimationImpl;
import com.shrcl.engineerprocess.domain.proxy.CostEstimationProcesssProxy;
import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.impl.RCEmployeeImpl;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.langlab.domain.organization.Party;
import edu.fudan.langlab.domain.security.ISystemUserService;
import edu.fudan.langlab.domain.workflow.ActivityNodeDef;
import edu.fudan.langlab.domain.workflow.BusinessProcess;
import edu.fudan.langlab.domain.workflow.Token;
import edu.fudan.langlab.domain.workflow.impl.BusinessProcessImpl;
import edu.fudan.mylang.common.StringExtensions;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("COSTESTIMATIONPROCESSS_TYPE")
public class CostEstimationProcesssImpl extends BusinessProcessImpl implements CostEstimationProcesss {
  public CostEstimationProcesssImpl() {
    super();
  }
  
  public String getProcessName() {
    return "项目成本估算流程";
  }
  
  public String getProcessType() {
    return "CostEstimationProcesss";
  }
  
  public ActivityNodeDef getActivityDef(final String activityId) {
    edu.fudan.langlab.domain.workflow.ActivityNodeDef result = new edu.fudan.langlab.domain.workflow.ActivityNodeDef();
    result.setActivityId(activityId);
    if("__end__".equals(activityId)){
    	result.setDescription("end");
    }else
    	result.setDescription(Enum.valueOf(com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.class, activityId).toString());
    return result;
    
  }
  
  public void _start(final EngineerCostEstimation costEstimation, final Token token) {
    BeanFactory _beanFactory = this.getBeanFactory();
    ISystemUserService _bean = _beanFactory.<ISystemUserService>getBean(ISystemUserService.class);
    Party _currentUserAsParty = _bean.getCurrentUserAsParty();
    this.starter = ((RCEmployee) _currentUserAsParty);
    boolean _notEquals = (!Objects.equal(this.starter, null));
    Validates.Assert(_notEquals, "\u672A\u8BBE\u7F6E\u5546\u52A1\u89D2\u8272");
    costEstimation.setBusinessProcess(((BusinessProcess) this));
    this.est = costEstimation;
  }
  
  public void start(final EngineerCostEstimation costEstimation) {
    edu.fudan.langlab.domain.workflow.Token token = getProcessManager().start(this,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalManagerEst.name());
    _start(costEstimation,token);
    getProcessManager().registTask(this, token, techManager(),getTechnicalManagerEst_task_message());
    systemExecute();
    String msg = getStart_log_message(costEstimation);
    getProcessManager().createActivity(this,"Create Process",msg);
    
    
  }
  
  public String getStart_log_message(final EngineerCostEstimation costEstimation) {
    return "\u542F\u52A8\u9879\u76EE\u6210\u672C\u4F30\u7B97\u6D41\u7A0B";
  }
  
  public void TechnicalManagerEst() {
  }
  
  public void _TechnicalManagerEst_reject(final String comment, final Token token) {
    Token BusinessManModify_token = getProcessManager().forwardTo(token,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.BusinessManModify.name());
    getProcessManager().registTask(this, BusinessManModify_token,salesMan(),getBusinessManModify_task_message());
  }
  
  public void TechnicalManagerEst_reject(final String comment) {
    edu.fudan.langlab.domain.workflow.Token token = getProcessManager().assertToken(this,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalManagerEst.name());
    _TechnicalManagerEst_reject(comment,token);
    systemExecute();
    String msg = getTechnicalManagerEst_Reject_log_message(comment);
    getProcessManager().createActivity(this,"技术经理估算.驳回修改",msg);
    
    
  }
  
  public String getTechnicalManagerEst_Reject_log_message(final String comment) {
    String _nullsafe = StringExtensions.nullsafe(comment);
    String _plus = ("\u9A73\u56DE\u4FEE\u6539:" + _nullsafe);
    return _plus;
  }
  
  public void _TechnicalManagerEst_accept(final String comment, final Token token) {
    Token TechnicalDirectorConfirm_token = getProcessManager().forwardTo(token,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalDirectorConfirm.name());
    getProcessManager().registTask(this, TechnicalDirectorConfirm_token,techDirector(),getTechnicalDirectorConfirm_task_message());
  }
  
  public void TechnicalManagerEst_accept(final String comment) {
    edu.fudan.langlab.domain.workflow.Token token = getProcessManager().assertToken(this,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalManagerEst.name());
    _TechnicalManagerEst_accept(comment,token);
    systemExecute();
    String msg = getTechnicalManagerEst_Accept_log_message(comment);
    getProcessManager().createActivity(this,"技术经理估算.同意",msg);
    
    
  }
  
  public String getTechnicalManagerEst_Accept_log_message(final String comment) {
    String _nullsafe = StringExtensions.nullsafe(comment);
    String _plus = ("\u540C\u610F:" + _nullsafe);
    return _plus;
  }
  
  public String getTechnicalManagerEst_task_message() {
    ServiceRequestInfo _requestInfo = this.est.getRequestInfo();
    String _projectName = _requestInfo.getProjectName();
    String _plus = ("\u9879\u76EE[" + _projectName);
    String _plus_1 = (_plus + "]\u4F30\u7B97");
    return _plus_1;
  }
  
  public void _BusinessManModify(final Token token) {
    Token TechnicalManagerEst_token = getProcessManager().forwardTo(token,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalManagerEst.name());
    getProcessManager().registTask(this, TechnicalManagerEst_token,techManager(),getTechnicalManagerEst_task_message());
  }
  
  public void BusinessManModify() {
    edu.fudan.langlab.domain.workflow.Token token = getProcessManager().assertToken(this,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.BusinessManModify.name());
    _BusinessManModify(token);
    systemExecute();
    String msg = getBusinessManModify_log_message();
    getProcessManager().createActivity(this,"商务修改项目信息",msg);
    
  }
  
  public String getBusinessManModify_log_message() {
    return "";
  }
  
  public String getBusinessManModify_task_message() {
    ServiceRequestInfo _requestInfo = this.est.getRequestInfo();
    String _projectName = _requestInfo.getProjectName();
    String _plus = ("\u8BF7\u4FEE\u6539[" + _projectName);
    String _plus_1 = (_plus + "]\u9879\u76EE\u4FE1\u606F");
    return _plus_1;
  }
  
  public void TechnicalDirectorConfirm() {
  }
  
  public void _TechnicalDirectorConfirm_reject(final String comment, final Token token) {
    Token TechnicalManagerEst_token = getProcessManager().forwardTo(token,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalManagerEst.name());
    getProcessManager().registTask(this, TechnicalManagerEst_token,techManager(),getTechnicalManagerEst_task_message());
  }
  
  public void TechnicalDirectorConfirm_reject(final String comment) {
    edu.fudan.langlab.domain.workflow.Token token = getProcessManager().assertToken(this,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalDirectorConfirm.name());
    _TechnicalDirectorConfirm_reject(comment,token);
    systemExecute();
    String msg = getTechnicalDirectorConfirm_Reject_log_message(comment);
    getProcessManager().createActivity(this,"技术总监审核.驳回修改",msg);
    
    
  }
  
  public String getTechnicalDirectorConfirm_Reject_log_message(final String comment) {
    String _nullsafe = StringExtensions.nullsafe(comment);
    String _plus = ("\u9A73\u56DE\u4FEE\u6539:" + _nullsafe);
    return _plus;
  }
  
  public void _TechnicalDirectorConfirm_accept(final String comment, final Token token) {
    Token BusinessManConfirm_token = getProcessManager().forwardTo(token,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.BusinessManConfirm.name());
    getProcessManager().registTask(this, BusinessManConfirm_token,salesMan(),getBusinessManConfirm_task_message());
  }
  
  public void TechnicalDirectorConfirm_accept(final String comment) {
    edu.fudan.langlab.domain.workflow.Token token = getProcessManager().assertToken(this,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.TechnicalDirectorConfirm.name());
    _TechnicalDirectorConfirm_accept(comment,token);
    systemExecute();
    String msg = getTechnicalDirectorConfirm_Accept_log_message(comment);
    getProcessManager().createActivity(this,"技术总监审核.同意",msg);
    
    
  }
  
  public String getTechnicalDirectorConfirm_Accept_log_message(final String comment) {
    String _nullsafe = StringExtensions.nullsafe(comment);
    String _plus = ("\u540C\u610F:" + _nullsafe);
    return _plus;
  }
  
  public String getTechnicalDirectorConfirm_task_message() {
    ServiceRequestInfo _requestInfo = this.est.getRequestInfo();
    String _projectName = _requestInfo.getProjectName();
    String _plus = ("\u5BA1\u6838[" + _projectName);
    String _plus_1 = (_plus + "]\u9879\u76EE\u4F30\u7B97");
    return _plus_1;
  }
  
  public void _BusinessManConfirm(final Token token) {
    Token __end___token = getProcessManager().forwardTo(token,"__end__");
    
  }
  
  public void BusinessManConfirm() {
    edu.fudan.langlab.domain.workflow.Token token = getProcessManager().assertToken(this,com.shrcl.engineerprocess.domain.CostEstimationProcesssStatus.BusinessManConfirm.name());
    _BusinessManConfirm(token);
    systemExecute();
    String msg = getBusinessManConfirm_log_message();
    getProcessManager().createActivity(this,"商务确认",msg);
    
  }
  
  public String getBusinessManConfirm_log_message() {
    return "";
  }
  
  public String getBusinessManConfirm_task_message() {
    ServiceRequestInfo _requestInfo = this.est.getRequestInfo();
    String _projectName = _requestInfo.getProjectName();
    String _plus = ("[" + _projectName);
    String _plus_1 = (_plus + "]\u9879\u76EE\u62A5\u4EF7\u5BA1\u6279\u5DF2\u5B8C\u6210\uFF0C\u8BF7\u53C2\u8003");
    return _plus_1;
  }
  
  @JoinColumn(name = "est_id")
  @ManyToOne(targetEntity = EngineerCostEstimationImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private EngineerCostEstimation est;
  
  public EngineerCostEstimation getEst() {
    return this.est;
  }
  
  public CostEstimationProcesss setEst(final EngineerCostEstimation est) {
    this.est = est;
    return this;			
    
  }
  
  @JoinColumn(name = "starter_id")
  @ManyToOne(targetEntity = RCEmployeeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCEmployee starter;
  
  public RCEmployee getStarter() {
    return this.starter;
  }
  
  public CostEstimationProcesss setStarter(final RCEmployee starter) {
    this.starter = starter;
    return this;			
    
  }
  
  public boolean _systemExecute() {
    boolean stateChanged = false;
    return stateChanged;
  }
  
  public static CostEstimationProcesss create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.CostEstimationProcesss costEstimationProcesss = new com.shrcl.engineerprocess.domain.impl.CostEstimationProcesssImpl();
    objectFactory.create(costEstimationProcesss);
    return costEstimationProcesss;			
    
  }
  
  public Party salesMan() {
    return this.starter;
  }
  
  public Party techManager() {
    RCEmployee _xblockexpression = null;
    {
      BeanFactory _beanFactory = this.getBeanFactory();
      TSCProcessRoleDAO _bean = _beanFactory.<TSCProcessRoleDAO>getBean(TSCProcessRoleDAO.class);
      TSCProcessRole _get = _bean.get();
      final RCEmployee res = _get.getFirstLevelVerifier();
      boolean _notEquals = (!Objects.equal(res, null));
      Validates.Assert(_notEquals, "\u672A\u8BBE\u7F6E\u6280\u672F\u7ECF\u7406");
      _xblockexpression = (res);
    }
    return _xblockexpression;
  }
  
  public Party techDirector() {
    RCEmployee _xblockexpression = null;
    {
      BeanFactory _beanFactory = this.getBeanFactory();
      TSCProcessRoleDAO _bean = _beanFactory.<TSCProcessRoleDAO>getBean(TSCProcessRoleDAO.class);
      TSCProcessRole _get = _bean.get();
      final RCEmployee res = _get.getSecondLevelVerifier();
      boolean _notEquals = (!Objects.equal(res, null));
      Validates.Assert(_notEquals, "\u672A\u8BBE\u7F6E\u6280\u672F\u603B\u76D1");
      _xblockexpression = (res);
    }
    return _xblockexpression;
  }
  
  public CostEstimationProcesssProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.CostEstimationProcesssProxy proxy = new com.shrcl.engineerprocess.domain.proxy.CostEstimationProcesssProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
